/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package register.ucm;
import java.sql.*;
import database.*;
import register.model.InputValueModel;
/**
 *
 * @author Donghui
 */
public class GenerateCountCode {
    private int count;
    private Select select=new Select();
    private ResultSet result;
    private InputValueModel value;
    private String sql;
    private String tp;
    public GenerateCountCode(InputValueModel temp)
    {
        select=new Select();
        value=temp;
    }

    public String getCount(String temp)
    {
        try
        {
        result=select.selectValue(temp);
        while(result.next())
        {
            count++;
        }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
//        System.out.println(count+ " results found");

        count++; // Offset one to initializate the count number
        
        if(count>0 && count<10)
        {
            tp="00"+count;
        }
        if(count>10 && count<100)
        {
            tp="0"+count;
        }
        if(count>100 && count<1000)
        {
            tp=String.valueOf(count);
        }
//        System.out.println("Count: " + tp);
        return tp;
    }
}
